/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tces.controller;

import com.tces.model.Category;
import com.tces.model.SubjectSchedule;
import com.tces.utils.ConnectionDAO;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;

/**
 *
 * @author arnolda
 */
public class CategoryDAO  extends ConnectionDAO {

    private static final Logger log = Logger.getLogger(CategoryDAO.class);
   /**
    * This will get all the categories that is visible
    * @return active category list
    * @throws Exception 
    */
    public static List<Category> getActiveCategories() throws Exception {
        List<Category> categoryList = new ArrayList<Category>();
        String sql = "SELECT * FROM categories WHERE category_visible=1";
        
        PreparedStatement preparedStatement = getConnectionObject().prepareStatement(sql);
        log.info(preparedStatement.toString());
        ResultSet rs = preparedStatement.executeQuery();
        Category category;
        while (rs.next()) {
            category = new Category();
            category.setCategoryID(rs.getInt("category_id"));
            category.setCategoryVisible(rs.getInt("category_visible"));
            category.setCategoryPercentage(rs.getDouble("category_percentage"));
            category.setCategoryName(rs.getString("categery_name"));
            categoryList.add(category);
        }
        closeConnection(getConnectionObject());
        return categoryList;
    }
}
